package com.cai.xiaobai.controller;


import com.alibaba.fastjson.JSONObject;
import com.cai.xiaobai.entity.DTO.fromInfo.addFrom.AddFromDTO;
import com.cai.xiaobai.result.Result;
import com.cai.xiaobai.service.IFromInfoService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 调查问卷表 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-05-13
 */
@RestController
@RequestMapping("/from-info")
@AllArgsConstructor
public class FromInfoController {

    private final IFromInfoService iFromInfoService;

    @PostMapping
    @Operation(summary = "创建问卷")
    public Result addFrom(@RequestBody AddFromDTO addFromDTO) {

        return iFromInfoService.addFrom(addFromDTO);
    }

    @GetMapping("/get-from")
    @Operation(summary = "查询的问卷", description = "如果不传openId就是查询全部")
    public Result getMyFrom(String openId, String status, Boolean flag) {
        return iFromInfoService.getMyFrom(openId, status, flag);
    }

    @PostMapping("delete")
    @Operation(summary = "删除问卷")
    public Result delete(@RequestBody JSONObject ids) {
        System.out.println("wed"+ids);
        return iFromInfoService.delete((String) ids.get("ids"));
    }

    @GetMapping("/get-info")
    @Operation(summary = "查看问卷的详细内容", description = "第二个参数flag如果传true的话表示也查看自己的填写的答案")
    public Result getFromInfo(String fromId) {
        return iFromInfoService.getFromInfo(fromId);
    }

}
